<template>
  <div>
    <div class="Unit-top">
      <h4 style="text-align: left; color: #126bff; margin-bottom: 20px">
        重点单位管理
      </h4>
      <el-form
        id="unit"
        ref="elForm"
        :model="formData"
        size="medium"
        label-width="115px"
      >
        <el-form-item
          label="所属行政区域:"
          prop="xzqydm"
          style="width: 450px; float: left"
        >
          <el-select
            v-model="formData.xzqydm"
            placeholder="请选择行政区域"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
            <el-option
              v-for="item in xzqydm"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="所属派出所:"
          prop="ssjwsq"
          style="width: 450px; float: left"
        >
          <el-cascader
            ref="xzCascade"
            placeholder="请选择或搜索所属行政区域"
            :options="optionsOne"
            :props="{ checkStrictly: true }"
            filterable
            :emitPath="emitPath"
            clearable
            style="float: left"
            :show-all-levels="false"
            v-model="formData.department_id"
            @change="handleChangexz"
            getCheckedNodes
            :style="{ width: '300px' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item
          label="单位名称:"
          prop="dwmc"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.dwmc"
            placeholder="请输入单位名称"
            clearable
            style="float: left"
            :style="{ width: '300px' }"
          >
          </el-input>
        </el-form-item>

        <el-form-item
          label="单位类型:"
          prop="dwlx"
          style="width: 450px; float: left"
        >
          <el-select
            v-model="formData.dwlx"
            clearable
            placeholder="请选择单位类型"
            style="float: left"
            @change="select"
            :style="{ width: '300px' }"
          >
            <el-option
              v-for="item in dwlx"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          label="法人代表姓名:"
          prop="fddbrxm"
          style="width: 450px; float: left"
        >
          <el-input
            v-model="formData.fddbrxm"
            placeholder="请输入法人代表"
            clearable
            :style="{ width: '300px' }"
            style="float: left"
          >
          </el-input>
        </el-form-item>

        <el-form-item
          label="添加时段:"
          prop="time"
          style="width: 450px; float: left"
        >
          <el-date-picker
            type="daterange"
            v-model="formData.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            :style="{ width: '300px' }"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            range-separator="至"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item size="small" style="float: right">
          <el-button
            @click="resetForm()"
            style="background-color: #e6effa; color: #126bff"
            >重置</el-button
          >
          <el-button
            type="primary"
            @click="submitForm(formData)"
            style="color: #ffffff; background-color: #126bff"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格 -->
    <div class="punch-content" style="width: 100%">
      <el-table
        ref="table"
        id="exportTable"
        :data="
          tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
        "
        style="width: 100%; cursor: pointer"
      >
        <el-table-column prop="ywlsh" label="序号" width="50" height="50px">
          <template slot-scope="scope">
            {{ scope.$index + 1 + (currentPage - 1) * pageSize }}
          </template>
        </el-table-column>
        <el-table-column prop="dwmc" label="单位名称" width="250">
        </el-table-column>
        <el-table-column prop="dwlx" label="单位类型" width="150">
        </el-table-column>
        <el-table-column prop="sjdz" label="实际办公地址" width="250">
        </el-table-column>
        <el-table-column prop="fddbrxm" label="法人代表姓名" width="150">
        </el-table-column>
        <el-table-column prop="fddbrlxfs" label="法人代表手机号" width="150">
        </el-table-column>
        <el-table-column prop="djzt" label="登记状态" width="150">
        </el-table-column>
        <el-table-column prop="gajgdwem" label="公安监管单位编码" width="150">
        </el-table-column>
        <el-table-column prop="xzqydm" label="行政区域" width="150">
        </el-table-column>
        <el-table-column prop="ssjwsq" label="所属派出所" width="200">
        </el-table-column>
        <el-table-column prop="zcdz" label="注册地址" width="200">
        </el-table-column>
        <el-table-column prop="tyshxydm" label="统一社会信用代码" width="200">
        </el-table-column>
        <el-table-column prop="fddbr_zjhm" label="法人代表证件号码" width="200">
        </el-table-column>
        <el-table-column prop="djjg" label="登记机关" width="150">
        </el-table-column>
        <el-table-column prop="clrq" label="成立日期" width="150">
        </el-table-column>
        <el-table-column prop="sjdz_dqwd" label="纬度" width="150">
        </el-table-column>
        <el-table-column prop="sjdz_dqjd" label="经度" width="150">
        </el-table-column>
        <el-table-column prop="create_time" label="添加时间" width="150">
        </el-table-column>
        <el-table-column class="cz" label="操作" width="80" fixed="right">
          <template slot-scope="scope">
            <div>
              <el-button
                @click="detailClick(scope.row)"
                type="text"
                size="small"
                >详情</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[9, 27, 54]"
        :page-size="pageSize"
        layout="total, prev, pager, next, sizes"
        :total="tableData.length"
        style="float: right; margin-top: 20px"
      >
      </el-pagination>
    </div>
    <!-- 弹窗 -->
    <div>
      <el-dialog
        title="详情"
        :visible.sync="dialogVisible"
        width="550px"
        top="0"
        style="border-radius: 20px"
      >
        <div style="display: flex; flex-wrap: wrap; text-align: left">
          <!-- <div class="upIpfo">
            <p>公安监管单位编码:{{ detaile.gajgdwem }}</p>
            <p>统一社会信用代码:{{ detaile.tyshxydm }}</p>
          </div> -->
          <div class="upIpfo">
            <p>单位名称：{{ detaile.dwmc }}</p>
            <p>单位类型：{{ detaile.dwlx }}</p>
          </div>
          <div class="upIpfo">
            <p>法定代表人姓名：{{ detaile.fddbrxm }}</p>
            <p class="text">法人代表手机号：{{ detaile.fddbrlxfs }}</p>
            <!-- <p class="text">注册地址：{{ detaile.zcdz }}</p> -->
          </div>
          <div class="upIpfo">
            <p>经度：{{ detaile.sjdz_dqjd }}</p>
            <p>纬度：{{ detaile.sjdz_dqwd }}</p>
          </div>
          <div class="upIpfo">
            <p>实际办公地址:{{ detaile.sjdz }}</p>
            <p>志愿者数量：{{ detaile.djzt }}</p>
          </div>
          <div class="upIpfo">
            <p>备注信息：{{ detaile.beizhuInfo }}</p>
            <p>添加时间：{{ detaile.create_time }}</p>
          </div>
          <!-- <div class="upIpfo">
            <p>行政区域：{{ detaile.xzqydm }}</p>
            <p>所属派出所：{{ detaile.ssjwsq }}</p>
          </div> -->
          <!-- <div class="upIpfo">
            <p>实际办公地址:{{ detaile.sjdz }}</p>
            <p>登记状态{{ detaile.djzt }}</p>
          </div> -->
          <!-- <div class="upIpfo">
            <p>法人代表证件号码:{{ detaile.fddbr_zjhm }}</p>
            <p class="text">法人代表手机号：{{ detaile.fddbrlxfs }}</p>
          </div> -->

          <!-- <div class="upIpfo">
            <p>登录密码：*******</p>
            <p>备注信息：{{ detaile.beizhuInfo }}</p>
          </div>
          <div class="upIpfo">
            <p>登记机关：{{ detaile.djjg }}</p>
            <p>成立日期：{{ detaile.clrq }}</p>
          </div> -->
        </div>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import { Loading } from "element-ui";
// import { searchSchool } from "@/api/school";
import { schoolList, police } from "@/api/police";
import VueCookie from "vue-cookies";

export default {
  name: "WARN",
  components: {},
  data() {
    return {
      headers: { "Content-Type": "multipart/form-data;charset=UTF-8" },
      title: "",
      addTitle: "添加单位",
      editInfo: "编辑信息",
      fileList: [],
      currentPage4: 4,
      // pages: {
      // 按页数查询数据
      currentPage: 1,
      pageSize: 9,
      pagesize: [9, 27, 54],
      value: "",
      dialogVisible: false,
      addDialogVisible: false,
      deleteChecked: false,
      mapDialogVisible: false,
      value2: false, // 审批默认通过
      // },
      dwlx: [
        {
          value: "中学",
          label: "中学",
        },
        {
          value: "小学",
          label: "小学",
        },
        {
          value: "幼儿园",
          label: "幼儿园",
        },
        {
          value: "学校",
          label: "学校",
        },
      ],
      xzqydm: [
        {
          text: "安次区",
          value: "安次区",
        },
        {
          text: "广阳区",
          value: "广阳区",
        },
        {
          text: "经济开发区",
          value: "经济开发区",
        },
        {
          text: "永清县",
          value: "永清县",
        },
        {
          text: "香河县",
          value: "香河县",
        },
        {
          text: "三河县",
          value: "三河县",
        },
        {
          text: "固安县",
          value: "固安县",
        },
        {
          text: "霸州市",
          value: "霸州市",
        },
        {
          text: "文安县",
          value: "文安县",
        },
        {
          text: "大城县",
          value: "大城县",
        },
        {
          text: "大厂回族自治县",
          value: "大厂回族自治县",
        },
      ],
      formData: {
        xzqydm: "",
        // ssjwsq: "",
        dwmc: "",
        dwlx: "",
        fddbrxm: "",
        time: "",
        department_id: "",
      },
      SearchData: {
        xzqydm: "",
        // ssjwsq: "",
        dwmc: "",
        dwlx: "",
        fddbrxm: "",
        begin_time: "",
        end_time: "",
        department_id: "",
      },
      detaile: {},
      tableData: [],
      optionsOne: [],
      emitPath: false,
      selectId: {
        dpid: "",
      },
    };
  },
  watch: {},
  created() {},
  mounted() {
    this.initSchoolList();
    this.initPolice();
  },
  methods: {
    // 初始化所属派出所级联选择器
    initPolice() {
      let that = this;
      this.selectId.token = this.$VueCookies.get("token");
      police(this.selectId).then((res) => {
        console.log(res);
        if (res.code == 200) {
          res.data.children.forEach((item) => {
            item.label = item.label.slice(6);
            item.children.forEach((m) => {
              m.label = m.label.slice(9);
            });
          });
          that.optionsOne.push(res.data);
          // that.optionsOne.children = ;
        } else if (res.code == 401) {
          alert(res.message);
        }
      });
    },
    // 选中派出所
    handleChangexz(e) {
      console.log(e[e.length - 1]);
      if (e[e.length - 1] != undefined) {
        this.formData.department_id = e[e.length - 1];
      } else {
        this.formData.department_id = "";
      }
      // console.log(e.pop());
    },
    // 学校列表初始化
    async initSchoolList() {
      let that = this;
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
        text: "搜索中",
      });
      // const token = VueCookie.get("token");
      await schoolList({
        token: VueCookie.get("token"),
      }).then((res) => {
        console.log(res);
        if (res.code == "200") {
          that.$nextTick(() => {
            // 以服务的方式调用的 Loading 需要异步关闭
            loadingInstance.close();
            console.log("成功");
            that.tableData = res.data.reverse();
            this.tableData.forEach((item, index) => {
              that.tableData[index].create_time = that
                .$moment(item.create_time * 1000)
                .format("YYYY-MM-DD HH:mm:SS");
            });
          });
        } else {
          console.log("失败");

          loadingInstance.close();
        }
      });
    },
    // 关闭详情页
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(() => {
          done();
        })
        .catch(() => {});
    },
    // 条件查询
    submitForm(formData) {
      let that = this;
      this.SearchData.dwlx = formData.dwlx;
      this.SearchData.dwmc = formData.dwmc;
      this.SearchData.fddbrxm = formData.fddbrxm;
      this.SearchData.xzqydm = formData.xzqydm;
      this.SearchData.department_id = formData.department_id;

      if (formData.time == [] || formData.time == null) {
        this.SearchData.end_time = "";
        this.SearchData.begin_time = "";
      } else {
        this.SearchData.end_time = formData.time[1];
        this.SearchData.begin_time = formData.time[0];
      }
      // + token: VueCookie.get("token"),
      this.SearchData.token = VueCookie.get("token");
      console.log(this.SearchData);
      let loadingInstance = Loading.service({
        target: document.querySelector(".el-table__body-wrapper"),
        text: "搜索中",
      });
      schoolList(this.SearchData).then((res) => {
        console.log(res);
        if (res.code == 200) {
          that.tableData = res.data;
          this.currentPage = 1;
          that.$nextTick(() => {
            loadingInstance.close();
            this.tableData.forEach((item, index) => {
              that.tableData[index].create_time = this.$moment(
                item.create_time * 1000
              ).format("YYYY-MM-DD HH:mm:SS");
              // console.log(moment(item.create_time * 1000).format("YYYY-MM-DD"));
            });
          });
        } else if (res.code == 400) {
          (that.tableData = []),
            that.$nextTick(() => {
              alert(res.message);
              loadingInstance.close();
            });
        }
      });
      console.log(formData);
    },
    // 查询条件重置
    resetForm() {
      this.$refs["elForm"].resetFields();
      this.currentPage = 1;
      this.initSchoolList();
    },
    // 详情
    detailClick(row) {
      console.log(row);
      this.dialogVisible = true;
      this.detaile = row;
    },
    // 分页操作
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    },
    // 单位类型选择
    select(e) {
      console.log(e);
    },
    cancel(formName) {
      this.addDialogVisible = false;
      this.$refs[formName].resetFields();
      this.initformdata();
    },
  },
};
</script>
<style  scoped lang="scss">
/deep/.el-range-separator {
  position: relative;
  top: 4px;
}
.Unit-top {
  // border: 1px red solid;
  padding: 10px;
  background-color: white;
  border-radius: 10px;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-content: center;
  justify-content: space-around;
  align-items: flex-start;
  box-sizing: border-box;
}
.Unit-top {
  width: calc(100%);
}

/deep/.el-range-editor--medium .el-range-separator {
  line-height: 21px;
  font-size: 14px;
}
/deep/ .el-range__icon {
  line-height: 21px;
}
// .auto-width {
//   width: "auto";
// }
.el-table {
  width: calc(100%);
}
/deep/.el-form-item__label {
  // border: 1px red solid;
  width: 100px !important;
}
/deep/.el-form-item {
  height: 50px;
}
/deep/.el-table th.el-table__cell {
  background-color: #ecf5ff !important;
  width: 64px;
  height: 21px;
  font-size: 16px;
  color: #13213b;
}
.punch-content {
  overflow: auto;
  margin-top: 20px;
  // border: 1px red solid;
  height: auto;
  background-color: white;
  border-radius: 10px;
  padding: 10px;
  box-sizing: border-box;
}

/deep/.el-table .el-table__cell {
  // border: 1px red solid;
  padding: 4px 0;
  box-sizing: border-box;
  text-overflow: ellipsis;
  vertical-align: middle;
  position: relative;
  text-align: center;
  line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
.upIpfo {
  display: flex;
  width: 100%;
  // border: 1px red solid;
  justify-content: space-between;
}
.upIpfo p {
  color: #13213b;
  font-size: 14px;
  font-weight: 400;
  width: 50%;
  margin-top: 10px;
  // border: 1px red solid;
  display: inline-block;
  span {
    display: inline-block;
    border: 1px red solid;
    width: 105px;
    text-align: right;
  }
  // background-color: skyblue;
}

/deep/.el-table__header-wrapper {
  // border: 1px red solid !important;
  border-radius: 10px 10px 0 0;
}
/deep/.el-table {
  border: 1px #d7dbe3 solid;
  border-radius: 10px;
}
/deep/.el-input--medium .el-input__icon {
  line-height: 30px;
}
/deep/.has-gutter tr th {
  color: black;
  text-align: center;
  border: 1px d7dbe3 solid;
  background-color: #ecf5ff;
}

/deep/.is-leaf {
  border: 1px #d7dbe3 solid !important;
  border-top: none !important;
  border-left: none !important;
}
/deep/.el-table__cell {
  text-align: center !important;
}
/deep/.el-input__suffix {
  top: -4px !important;
  right: 20px;
}
// /deep/.el-table__row {
//   border: 1px red solid !important;
// }
/deep/.el-dialog {
  border-radius: 15px !important;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
/deep/.el-dialog__header {
  text-align: left;
  font-weight: 600;
}
/deep/.el-dialog__body {
  padding: 0 20px 20px 20px !important;
}

/deep/.el-input--suffix .el-input__inner {
  padding-right: 0px !important;
}
/deep/.el-range-editor.el-input__inner {
  position: relative !important;
  right: 20px !important;
}
/deep/.el-input__inner {
  border: 1px solid #d7dbe3 !important;
  background-color: white !important;
}
// el-table_1_column_5   el-table__cell
.rowText {
  text-overflow: ellipsis;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  /*第几行裁剪*/
  -webkit-box-orient: vertical;
}
/deep/.el-switch__label.is-active {
  color: #ff4444;
}
.success {
  margin-right: 15px;
  width: 76px;
  height: 36px;
  background: #1cdc7c;
  border-radius: 10px;
  opacity: 1;
  border: none;
  color: #ffffff;
}
.refuse {
  width: 76px;
  height: 36px;
  background: #ff4444;
  border-radius: 10px;
  opacity: 1;
  border: none;
  color: #ffffff;
}
.btn {
  margin: 0 10px;
  // width: 108px;
  height: 36px;
  background-color: #126bff;
  border-radius: 8px 8px 8px 8px;
  opacity: 1;
  color: #ffffff;
  font-size: 16px;
  font-family: Microsoft YaHei-Regular, Microsoft YaHei;
  font-weight: 400;
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn:nth-of-type(4) {
  background-color: #ff4444 !important;
}
.addFormdata {
  margin-bottom: 16px;
}
.addFormdata .el-form-item {
  display: flex;
  width: 47%;
}
::v-deep.Unit-top .el-form-item--medium ::v-deep.el-form-item__content {
  margin-left: 0px !important;
  width: 100% !important;
}
/deep/.el-form-item__content {
  width: 100% !important;
}
[data-v-f1c6d362] .el-form-item__content {
  margin-left: 0px !important;
}
.addFormdata .el-select {
  width: 100% !important;
}
/deep/.addFormdata .el-form-item__label {
  width: 190px !important;
}
/deep/.el-input-group__append {
  width: 25px !important;
  background: rgba(18, 107, 255, 0.05);
  border-radius: 0px 8px 8px 0px;
  opacity: 1;
  border: 1px solid #126bff;
  color: #126bff;
}
.el-input-group__append,
.el-input-group__prepend {
  padding: 0 10px;
}
#unit {
  /deep/.el-form-item__content {
    margin-left: 0px !important;
  }
  /deep/.el-form-item--small {
    float: right !important;
  }
}
</style>

